package com.skyz.base.application;

import android.app.Application;

import com.hjq.toast.ToastUtils;
import com.hjq.toast.config.IToastStyle;
import com.skyz.base.manager.ActivityManager;
import com.skyz.base.manager.CrashHandler;
import com.skyz.base.manager.CrashManager;
import com.skyz.base.manager.EnvironmentManager;
import com.skyz.base.manager.FileLoggerManager;
import com.skyz.base.manager.RetrofitManager;
import com.skyz.base.manager.SystemManager;

import java.util.List;

import okhttp3.OkHttpClient;

public abstract class BaseApplication extends Application {

    private static Application sApplication;

    @Override
    public void onCreate() {
        super.onCreate();

        setApplication(this);

        ToastUtils.init(this, initToastStyle());

        ActivityManager.getInstance().init(this);

        FileLoggerManager.getInstance().init(this);

        SystemManager.getInstance().init(this);

        List<EnvironmentManager.Environment> environments = initEnvironmentList();
        EnvironmentManager.getInstance().init(this, environments);

        OkHttpClient okHttpClient = initOkHttpClient();
        RetrofitManager.getInstance().init(environments, okHttpClient);

        initApplication();
    }

    protected abstract IToastStyle<?> initToastStyle();

    protected abstract void initApplication();

    protected abstract List<EnvironmentManager.Environment> initEnvironmentList();

    protected abstract OkHttpClient initOkHttpClient();

    private static void setApplication(Application application) {
        sApplication = application;
    }

    public static Application getApplication() {
        return sApplication;
    }

    public static EnvironmentManager.Environment getEnvironment() {
        return EnvironmentManager.getInstance().getCheckedEnvironment();
    }
}
